// + warunki brzegowe
#include "DateTest.h"

using namespace kc_sf;

void DateTest::constructionTest()
{
	BOOST_REQUIRE_NO_THROW( new Date( 21, 4, 1985, 12, 30, 0, '+', 100 ) );	// dobre wartości
	BOOST_REQUIRE_NO_THROW( new Date( 31, 12, 1900, 23, 60, 61, '-', 0 ) );	// automatycznie poprawiane wartości
	BOOST_REQUIRE_THROW( new Date( 0, 12, 1985, 12, 30, 0, '-', 0),
						Date::DateError );		// błąd dnia
	BOOST_REQUIRE_THROW( new Date( 20, 13, 1985, 12, 30, 0, '-', 0),
						Date::DateError );		// błąd miesiąca
	BOOST_REQUIRE_THROW( new Date( 20, 10, 1000, 12, 30, 0, '-', 0),
						Date::DateError );		// błąd roku
	BOOST_REQUIRE_THROW( new Date( 21, 4, 1985, 12, 30, 0, '+', 9999 ),
						Date::DateError );		// błąd strefy

	t_date = DatePtr( new Date( 21, 4, 1985, 12, 30, 0, '+', 100 ) );
}

void DateTest::getSetMethodsTest()
{
	t_date = DatePtr( new Date( 21, 4, 1985, 12, 30, 0, '+', 100 ) );
	BOOST_REQUIRE( t_date->dayName().empty() );
	BOOST_REQUIRE_EQUAL( t_date->day(), static_cast<unsigned int>( 21 ) );
	BOOST_REQUIRE_EQUAL( t_date->month(), static_cast<unsigned int>( 4 ) );
	BOOST_REQUIRE_EQUAL( t_date->year(), static_cast<unsigned int>( 1985 ) );
	BOOST_REQUIRE_EQUAL( t_date->hour(), static_cast<unsigned int>( 12 ) );
	BOOST_REQUIRE_EQUAL( t_date->minutes(), static_cast<unsigned int>( 30 ) );
	BOOST_REQUIRE_EQUAL( t_date->seconds(), static_cast<unsigned int>( 0 ) );
	BOOST_REQUIRE_EQUAL( t_date->zone().first, '+' );
	BOOST_REQUIRE_EQUAL( t_date->zone().second, static_cast<unsigned int>( 100 ) );

	t_date->setDayName( "Mon" );
	BOOST_REQUIRE_EQUAL( t_date->dayName(), "Mon" );
	BOOST_REQUIRE_EQUAL( t_date->setDay( 0 ), false );
	BOOST_REQUIRE_EQUAL( t_date->day(), static_cast<unsigned int>( 21 ) );
	BOOST_REQUIRE( t_date->setDay( 31 ) );
	BOOST_REQUIRE_EQUAL( t_date->day(), static_cast<unsigned int>( 30 ) );
	BOOST_REQUIRE_EQUAL( t_date->setMonth( 13 ), false );
	BOOST_REQUIRE_EQUAL( t_date->month(), static_cast<unsigned int>( 4 ) );
	BOOST_REQUIRE( t_date->setYear( 2008 ) );
	BOOST_REQUIRE_EQUAL( t_date->year(), static_cast<unsigned int>( 2008 ) );
	t_date->setHour( 25 );
	BOOST_REQUIRE_EQUAL( t_date->hour(), static_cast<unsigned int>( 23 ) );
	t_date->setMinutes( 60 );
	BOOST_REQUIRE_EQUAL( t_date->minutes(), static_cast<unsigned int>( 59 ) );
	t_date->setSeconds( 61 );
	BOOST_REQUIRE_EQUAL( t_date->seconds(), static_cast<unsigned int>( 60 ) );
	BOOST_REQUIRE_EQUAL( t_date->setZone( '.', 1 ), false );
	BOOST_REQUIRE_EQUAL( t_date->zone().first, '+' );
	BOOST_REQUIRE_EQUAL( t_date->zone().second, static_cast<unsigned int>( 100 ) );
	BOOST_REQUIRE( t_date->setZone( '-', static_cast<unsigned int>( 200 ) ) );
	BOOST_REQUIRE_EQUAL( t_date->zone().first, '-' );
	BOOST_REQUIRE_EQUAL( t_date->zone().second, static_cast<unsigned int>( 200 ) );
}

void DateTest::compareTest()
{
	compare();
	compareDay();
	compareMonth();
	compareYear();
	compareZone();
}

// Pomocnicze -------------------------------------------------------- //
	
void DateTest::compare()
{
	t_date = DatePtr( new Date( 21, 4, 1985, 12, 30, 0, '+', 100 ) );

	Date equal( 21, 4, 1985, 12, 30, 0, '+', 100 );
	Date equal_diff_zone(21, 4, 1985, 10, 30, 0, '-', 100 );

	Date smaller_day( 11, 4, 1985, 12, 30, 0, '+', 100 );
	Date smaller_month( 21, 1, 1985, 12, 30, 0, '+', 100 );
	Date smaller_year( 21, 4, 1984, 12, 30, 0, '+', 100 );
	Date smaller_time( 21, 4, 1985, 11, 30, 0, '+', 100 );
	Date smaller_time_diff_zone( 21, 4, 1985, 6, 30, 0, '-', 300 );

	Date bigger_day( 30, 4, 1985, 12, 30, 0, '+', 100 );
	Date bigger_month( 21, 10, 1985, 12, 30, 0, '+', 100 );
	Date bigger_year( 21, 4, 2000, 12, 30, 0, '+', 100 );
	Date bigger_time( 21, 4, 1985, 12, 45, 0, '+', 100 );
	Date bigger_time_diff_zone( 21, 4, 1985, 15, 45, 0, '+', 300 );

	BOOST_CHECK_EQUAL( t_date->compare( equal ), EQUAL );
	BOOST_CHECK_EQUAL( t_date->compare( equal_diff_zone ), EQUAL );

	BOOST_CHECK_EQUAL( t_date->compare( bigger_day ), SMALLER );
	BOOST_CHECK_EQUAL( t_date->compare( bigger_month ), SMALLER );
	BOOST_CHECK_EQUAL( t_date->compare( bigger_year ), SMALLER );
	BOOST_CHECK_EQUAL( t_date->compare( bigger_time ), SMALLER );
	BOOST_CHECK_EQUAL( t_date->compare( bigger_time_diff_zone ), SMALLER );

	BOOST_CHECK_EQUAL( t_date->compare( smaller_day ), BIGGER );
	BOOST_CHECK_EQUAL( t_date->compare( smaller_month ), BIGGER );
	BOOST_CHECK_EQUAL( t_date->compare( smaller_year ), BIGGER );
	BOOST_CHECK_EQUAL( t_date->compare( smaller_time ), BIGGER );
	BOOST_CHECK_EQUAL( t_date->compare( smaller_time_diff_zone ), BIGGER );
}

void DateTest::compareDay()
{
	t_date = DatePtr( new Date( 21, 4, 1985, 12, 30, 0, '+', 100 ) );

	Date equal_diff_zone( 21, 4, 1985, 10, 30, 0, '-', 100 );
	Date equal_diff_zone_hour( 22, 4, 1985, 1, 30, 0, '+', 1400 );
	Date bigger_day( 30, 4, 1985, 12, 30, 0, '+', 100 );
	Date smaller_day( 11, 4, 1985, 12, 30, 0, '+', 100 );
	
	BOOST_CHECK_EQUAL( t_date->compareDay( equal_diff_zone ), EQUAL );
	BOOST_CHECK_EQUAL( t_date->compareDay( equal_diff_zone_hour ), EQUAL );
	BOOST_CHECK_EQUAL( t_date->compareDay( smaller_day ), BIGGER );
	BOOST_CHECK_EQUAL( t_date->compareDay( bigger_day ), SMALLER );
}

void DateTest::compareMonth()
{
	t_date = DatePtr( new Date( 30, 4, 1985, 12, 30, 0, '+', 100 ) );

	Date equal_diff_zone( 30, 4, 1985, 10, 30, 0, '-', 100 );
	Date equal_diff_zone_hour( 01, 5, 1985, 1, 30, 0, '+', 1400 );

	Date bigger_month( 30, 10, 1985, 12, 30, 0, '+', 100 );
	Date smaller_month( 30, 1, 1985, 12, 30, 0, '+', 100 );
		
	BOOST_CHECK_EQUAL( t_date->compareMonth( equal_diff_zone ), EQUAL );
	BOOST_CHECK_EQUAL( t_date->compareMonth( equal_diff_zone_hour ), EQUAL );
	BOOST_CHECK_EQUAL( t_date->compareMonth( smaller_month ), BIGGER );
	BOOST_CHECK_EQUAL( t_date->compareMonth( bigger_month ), SMALLER );
}

void DateTest::compareYear()
{
	t_date = DatePtr( new Date( 31, 12, 1985, 12, 30, 0, '+', 100 ) );

	Date equal_diff_zone( 31, 12, 1985, 10, 30, 0, '-', 100 );
	Date equal_diff_zone_hour( 1, 1, 1986, 1, 30, 0, '+', 1400 );
	Date bigger_year( 31, 12, 2000, 12, 30, 0, '+', 100 );
	Date smaller_year( 31, 12, 1984, 12, 30, 0, '+', 100 );
	
	BOOST_CHECK_EQUAL( t_date->compareYear( equal_diff_zone ), EQUAL );
	BOOST_CHECK_EQUAL( t_date->compareYear( equal_diff_zone_hour ), EQUAL );
	BOOST_CHECK_EQUAL( t_date->compareYear( smaller_year ), BIGGER );
	BOOST_CHECK_EQUAL( t_date->compareYear( bigger_year ), SMALLER );
}

void DateTest::compareZone()
{
	t_date = DatePtr( new Date( 21, 4, 1985, 12, 30, 0, '+', 100 ) );

	Date equal( 21, 4, 1985, 12, 30, 0, '+', 100 );
	Date equal_diff_zone( 21, 4, 1985, 10, 30, 0, '-', 100 );
	Date smaller_zone( 21, 4, 1985, 12, 30, 0, '-', 1000 );
	Date bigger_zone( 21, 4, 1985, 12, 30, 0, '+', 1000 );
	
	BOOST_CHECK_EQUAL( t_date->compareZone( equal ), EQUAL );
	BOOST_CHECK_EQUAL( t_date->compareZone( smaller_zone ), BIGGER );
	BOOST_CHECK_EQUAL( t_date->compareZone( bigger_zone ), SMALLER );
}

